<?php
    $select_m=mysql_query('SELECT * FROM messages WHERE `to`="'.$_SESSION['username'].'" ORDER BY date DESC');
	if(mysql_num_rows($select_m)>0){
	
	echo '
	<table border="0" style="border-collapse: collapse; margin-left: 20px; width: 650px; text-shadow: 1px 1px 1px #fff;">
	<tr style="background-color: #b7b6b6;"><td style="width: 150px; " align="center"><p><b>Тема</b></p></td><td style="width: 130px;" align="center"><p><b>От</b></p></td><td style="width: 100px;" align="center"><p><b>Изпратено</b></p></td><td style="width: 150px;" align="center"><p><b>Опции</b></p></td></tr>
	';
	
	while($row_m=mysql_fetch_assoc($select_m)){
	if($row_m['read']==0){
	echo '<tr><td></td></tr>';
	echo '<tr><td></td></tr>';
	echo '<tr><td></td></tr>';
	
	echo '<tr style="height: 40px; background-color: #ede7e7; text-shadow: 3px 3px 3px #fff;"><td style="padding-left: 10px;"><b>'.$row_m['topic'].'</b></td>
	<td style="text-align: center"><b>'.$row_m['from'].'</b></td><td style="text-align: center"><b>'.date('d-m-Y', $row_m['date']).'</b></td>
	<td style="padding-right: 10px; text-align: center;">
	<a href="view.php?id='.$row_m['id'].'&amp;mode=view&amp;in=in"><img src="../img/see.png" alt="see"/></a>
	<a href="view.php?id='.$row_m['id'].'&amp;mode=delete&amp;in=in"><img src="../img/delete.png" alt="delete"/></a></td></tr>
	<tr><td colspan="4" style="padding-left: 10px; padding-right: 10px;"><hr /></td></tr>';
	}
	else{
	echo '<tr><td></td></tr>';
	echo '<tr><td></td></tr>';
	echo '<tr><td></td></tr>';
	
	echo '<tr style="height: 40px; background-color: #ede7e7; text-shadow: 3px 3px 3px #fff;"><td style="padding-left: 10px;"><b>'.$row_m['topic'].'</b></td>
	<td style="text-align: center">'.$row_m['from'].'</td><td style="text-align: center">'.date('d-m-Y', $row_m['date']).'</td>
	<td style="padding-right: 10px; text-align: center;">
	<a href="view.php?id='.$row_m['id'].'&amp;mode=view&amp;in=in"><img src="../img/see.png" alt="see"/></a>
	<a href="view.php?id='.$row_m['id'].'&amp;mode=delete&amp;in=in"><img src="../img/delete.png" alt="delete"/></a></td></tr>
	<tr><td colspan="4" style="padding-left: 10px; padding-right: 10px;"><hr /></td></tr>';
	}
	}
	echo '
	</table>
	'; 
	}
	else{
	   echo "<p style='text-align: center; font-weight: bold;'>Няма нови съобщения</p>";
	}
?>